package lambda;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author : 李红磊
 * @version :1.0
 * @date : 2021/10/9 9:18
 * @description : Stream流
 */
public class Demo1 {

    List<Student> students = Arrays.asList(new Student("朱元璋", 64, 1.76f),
            new Student("朱允炆", 24, 1.76f),
            new Student("朱棣", 24, 1.76f),
            new Student("朱高炽", 24, 1.76f),
            new Student("朱瞻基", 24, 1.76f),
            new Student("朱祁镇", 24, 1.76f),
            new Student("朱祁钰", 24, 1.76f),
            new Student("主见深", 24, 1.76f),
            new Student("朱佑樘", 24, 1.76f),
            new Student("朱厚照", 24, 1.76f),
            new Student("朱厚熜", 24, 1.76f),
            new Student("朱载垕", 24, 1.76f),
            new Student("朱翊钧", 24, 1.76f),
            new Student("朱常洛", 24, 1.76f),
            new Student("朱由校", 24, 1.76f),
            new Student("朱由检", 14, 1.76f));

    @Test
    public void testSteam1() {
        students.stream().filter((x) -> x.getAge() >= 18).forEach(System.out::println);

    }



    @Test
    public void testSteam2() {

        Optional<Integer> integer = students.stream()
                .map(Student::getAge)
                .collect(Collectors.maxBy(Integer::compare));

        System.out.println(integer);

    }


}
